﻿using swe.Core;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace swe.Test
{


	/// <summary>
	///This is a test class for StateMachineBuilderTest and is intended
	///to contain all StateMachineBuilderTest Unit Tests
	///</summary>
	[TestClass()]
	public class StateMachineBuilderTest
	{
		public class Lamp
		{
			public bool IsOn { get; set; }
		}

		private StateMachine<Lamp, Lamp> _lampSm;
		private Lamp _lamp;

		[TestMethod()]
		public void TestOnOffSwitch()
		{
			_lamp = new Lamp { IsOn = false };
			_lampSm = (StateMachine<Lamp,Lamp>)StateMachine<Lamp, Lamp>.Create("On")
				.State("On", (s, l) =>
								{
									l.IsOn = true;
									return StateMachine.NamedState("Off");
								})
				.State("Off", (s, l) =>
								{
									l.IsOn = false;
									return StateMachine.NamedState("On");
								})
				.BindTo(_lamp);

			Assert.AreEqual(null, _lampSm.CurrentState);
			_lampSm.Process();
			Assert.AreEqual("On", _lampSm.CurrentState);
		}

		[TestMethod]
		public void TurnOn()
		{
			TestOnOffSwitch();

			Assert.AreEqual(false, _lampSm.Eos);
			Assert.AreEqual(true, _lamp.IsOn);

			_lampSm.Process();
			Assert.AreEqual(false, _lamp.IsOn);
		}
	}
}
